<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>计时器</title>
	<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
	<div id="app">
		<counter ref="one" @change="handleChange"></counter>
		<counter ref="two" @change="handleChange"></counter>
		{{total}}
	</div>
	<script>
		Vue.component("counter",{
			data: function() {
				return {
					number: 0
				}
			},
			template: "<div @click='handleCounterClick'>{{number}}</div>",
			methods: {
				handleCounterClick: function() {
					this.number ++
					this.$emit("change")
				}
			}
		})

		new Vue({
			el: "#app",
			data: {
				total: 0
			},
			methods: {
				handleChange: function() {
					this.total = this.$refs.one.number + this.$refs.two.number
				}
			}
		})
	</script>
</body>
</html>